<template>
	<view>
		<view class="scroll-view">
			<scroll-view scroll-y="true" class="scroll-l" :scroll-top="scroll_top" :style="{height: wh + 'px'}">
				<block v-for="(item,i) in cate" :key="i" >
					<view :class="['scroll-item',i===active?'active':'']" @click="activeChangeed(i)"> {{item.cat_name}}</view>
				</block>
			</scroll-view>
			<scroll-view scroll-y="true" class="scroll-r" :style="{height: wh + 'px'}">
				<block v-for="(item,i2) in cateList" :key="i2">
					<view class="cate-lv2">
						<text>/{{item.cat_name}}/</text>
					</view>
					<view class="cate-list3">
						<view class="cate-lv-3" v-for="(item3,i3) in item.children" :key="i3" @click="gotoGoodsList(item3)"> 
							<image :src="item3.cat_icon" mode=""></image>
							<text>{{item3.cat_name}}</text>
						</view>
					</view>
				</block>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cate:[],
				active:0,
				cateList:[],
				wh:0,
				scroll_top:0
			};
		},
		onLoad() {
		 	 this.getCate()
			 //获得当前系统信息
			 const sysInfo=uni.getSystemInfoSync()
			 this.wh=sysInfo.windowHeight
		},
		methods:{
		 	async getCate(){
				let {data:res} =await uni.$http.get('/api/public/v1/categories')
				if(res.meta.status!==200) return uni.$showMsg()
				this.cate=res.message
				this.cateList=res.message[0].children
			},
			activeChangeed(i){
				this.active=i
				this.cateList=this.cate[i].children
				this.scroll_top=this.scroll_top==0?1:0
			},
			gotoGoodsList(item3){
				uni.navigateTo({
					url:'/subpak/goods_list/goods_list?cid='+item3.cat_id
				})
			}
		}
	}
</script>

<style lang="scss">
	.scroll-view{
		height: 100%;
		display: flex;
		.scroll-l{
			width: 120px;
			.scroll-item{
				padding: 4px;
				margin-bottom: 3px;
				font-size: 15px;
				text-align: center;
				background-color: #f7f7f7;
				position:relative;
				&.active{
					background-color: #FFFFFF;
					&::after{
						content: '';
						top: 50%;;
						transform: translateY(-50%);
						height: 100%;
						border-left: 4px solid #DD524D;
						position: absolute;
						right: 0;
					}
				}
				
			}
		}
		.scroll-r{
			.cate-lv2{
				text-align: center;
				margin-top: 15px;
			}
			.cate-list3{
				display: flex;
				flex-wrap: wrap;
				text-align: center;
				.cate-lv-3 {
					width: 33.33%;
					display: flex;
					flex-direction: column;
					image{
						width: 60px;
						height: 60px;
						margin:auto;
					}
				}
			}
		}
		
	}
</style>
